jQuery(document).on("pageinit", "[data-role='page'][data-pagetype='products']", function(event) {
    var page = jQuery(this);
 
    jQuery.getJSON(URL_ACTION_PROD_CATEGORIES, {}, function(results) {
        var ops = [];
        jQuery.each(results, function(i, op){
            ops.push("<option value='"+op.id+"'>"+op.name+"</option>");
        });
        page.find("select[name=categories]").append(ops.join("")).trigger("change");
    });

    page.find(":button.search").click(function(event) {
        event.preventDefault();
        event.stopPropagation();

        var keywords = jQuery.trim(page.find("input.keywords").val());
        var category = page.find("select[name=categories]").val();

        if(category == "choose-one"){
            var errmsg = page.find("div.errmsg");
            errmsg.find("p").html("请选择分类!");
            errmsg.popup("open");
            return;
        }

        var params = {
            keywords: keywords ? keywords : 'null',
            category: category,
        };

        jQuery.mobile.changePage(URL_VIEW_PROD_LIST, {type: "get", data: params, transition: "slide", reverse: false, changeHash: true });
    });   
});

